package file_cleaner

import (
	"file-cleaner/internal/file_cleaner/config"
	"file-cleaner/internal/file_cleaner/options"
	"github.com/ClessLi/component-base/pkg/app"
)

const commandDesc = `the file-cleaner is a tool used to perform redundant deduplication on small files stored similar to "fastdfs" and reduce disk overhead.
Support high concurrency coroutine retrieval and file cleaning.

Find more file-cleaner information at:
    https://gitee.com/cosNeaby/file-cleaner/blob/master/docs/guide/en-US/cmd/file-cleaner.md`

func NewApp(basename string) *app.App {
	opts := options.NewOptions()
	application := app.NewApp("file-cleaner",
		basename,
		app.WithOptions(opts),
		app.WithDescription(commandDesc),
		app.WithDefaultValidArgs(),
		app.WithRunFunc(run(opts)),
	)

	return application
}

func run(opts *options.Options) app.RunFunc {
	return func(basename string) error {
		cfg, err := config.CreateConfigFromOptions(opts)
		if err != nil {
			return err
		}

		return Run(cfg)
	}
}
